var public = {
    fn_resize: function () {
        Zepto(window).resize(function () {
            public.fn_unit();
            public.fn_tableFixed();
        })
    },
    // table单位大屏位置
    fn_unit: function () {
        var ow = document.documentElement.clientWidth;
        if (ow >= 750) {
            Zepto('.aim-table .unit').addClass('inline-block')
        }else{
            Zepto('.aim-table .unit').removeClass('inline-block')
        }
    },
    fn_hoverBottomToggle: function () {
        var windowTop = 0; //初始话可视区域距离页面顶端的距离

        Zepto('.scroll-body').scroll(function () {
            var scrolls = Zepto(this).scrollTop(); //获取当前可视区域距离页面顶端的距离

            if (scrolls <= 0) { // 处理回弹
                return
            } else {
                if (scrolls >= windowTop) {
                    windowTop = scrolls;

                    Zepto(".hoverBottomToggle").animate({
                        'bottom': '-0.78rem'
                    }, 'fast')
                    // .hide()
                } else {
                    windowTop = scrolls;
                    Zepto(".hoverBottomToggle").animate({
                        'bottom': '0.08rem'
                    }, 'fast')
                    // .show()
                }
            }
        });
    },
    fn_tableFixed: function () {
        var ow = document.documentElement.clientWidth;

        var fitCell = Zepto('.fixed-header .fit-cell')
        var scrollBody = Zepto('.scroll-body')
        Zepto('.empty').css('width', ow)
        if (scrollBody.length) {
            Zepto('.scroll-body th').map(function (index, item) {
                var _width = Zepto(this).width()
                fitCell.eq(index).width(_width)
            })
        }
    },
    // 清空
    fn_clear: function () {
        var aim = Zepto('.search-input-inner')
        if (aim.length) {
            aim.on('keyup', 'input', function () {
                var text = Zepto.trim(Zepto(this).val());
                if (text.length > 0) {
                    Zepto('.icon-clear').show()
                } else {
                    Zepto('.icon-clear').hide()
                }
            })
            mui('.search-input-inner').on('tap', '.icon-clear', function () {
                Zepto(this).siblings('input').val('')
                Zepto(this).hide()
            })
        }


    },
    // 禁止ios弹性
    fn_stop: function () {
        document.querySelector('body').addEventListener('touchmove', function (e) {
            var aim = document.querySelector('.scroll-body')
            if (aim) {
                if (!aim.contains(e.target)) {
                    e.preventDefault();
                }
            }

        })
    },
    // 禁止滚动到头和底而引起ios弹性再次触发
    fn_stop_link: function (el) {
        if (el) {
            el.addEventListener('touchstart', function () {
                var top = el.scrollTop
                totalScroll = el.scrollHeight
                currentScroll = top + el.offsetHeight;
                if (top === 0) {
                    el.scrollTop = 1;
                } else if (currentScroll === totalScroll) {
                    el.scrollTop = top - 1;
                }
            });
        }

    },
    fn_stop_div: function () {
        public.fn_stop_link(document.querySelector('.scroll-body'))
    },


    init: function () {
        this.fn_resize();
        this.fn_unit();
        // this.fn_hoverBottomToggle();
        this.fn_tableFixed();
        this.fn_clear();
        this.fn_stop();
        this.fn_stop_div();
    },
}
$(function () {
    public.init();
})